package com.xu.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: 生如夏花
 * @Date: 2022/3/15 17:07
 */
@Configuration
public class FanoutConfig {
    /**
     * 声明一个交换机
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange ("test.fanout");
    }

    /**
     * 声明一个队列
     * @return
     */
    @Bean
    public Queue queue1(){
        return new Queue("fanout.queue1");
    }

    /**
     * 绑定交换机与队列
     * @param queue1
     * @param fanoutExchange
     * @return
     */
    @Bean
    public Binding fanoutBinding1(Queue queue1,FanoutExchange fanoutExchange){
        return BindingBuilder
                .bind (queue1)
                .to (fanoutExchange);
    }
    @Bean
    public Queue queue2(){
        return new Queue ("fanout.queue2");
    }

    @Bean
    public Binding fanoutBinding2(Queue queue2,FanoutExchange fanoutExchange){
        return BindingBuilder
                .bind (queue2)
                .to (fanoutExchange);
    }
}
